home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / asc2pas.zip / ASC2PAS.PAS < prev    next >
Pascal/Delphi Source File  |  1992-06-08  |  4KB  |  134 lines

  1. {$R-}    {Range checking off}
  2. {$B-}    {Boolean complete evaluation off}
  3. {$S-}    {Stack checking off}
  4. {$I+}    {I/O checking on}
  5. {$N-}    {No numeric coprocessor}
  6. {$M 65500,16384,655360} {Turbo 3 default stack and heap}
  7.  
  8. { Program ASC2PAS (TM) source code Copyright (C) '88  Bruce L. Rosenberg.
  9.   This program is being made available to individuals on a royalty-free
  10.   basis for noncommercial use.  Contact the author for licensing information.
  11.   For further information contact:
  12.   Bruce L. Rosenberg, 23 N. Chelsea Ave., Atlantic City, NJ 08405,
  13.   (609) 345-4712.
  14. }
  15.  
  16. program ASC2PAS;   { completed 4-8-88 }
  17.  
  18. Uses
  19.   Crt,
  20.   Dos;
  21.  
  22. type
  23.      ascii = set of 0..127;
  24.      askstrtype = string[65];
  25.      fnstrtype = string[14];
  26.  var
  27.      inf:         text;
  28.      outf:        text;
  29.      line:           string[80];
  30.      LocOnLine,CharCount :  integer;
  31.      infname:       fnstrtype;
  32.      outfname:       fnstrtype;
  33.      askstr : askstrtype;
  34.      AskResp : char;
  35. const
  36.       PrnChars:     ascii = [32..126];
  37.       newline:     ascii = [10,13];
  38. {============================================================================}
  39. procedure name_outfile(infname : fnstrtype; VAR outfname : fnstrtype);
  40. var
  41. dotpos,nl : integer;
  42. tstr : string[8];
  43. begin
  44.   for nl := 1 to length(infname) do
  45.     begin
  46.       if ord(infname[nl]) = 46 then dotpos := nl;
  47.     end;
  48.   if dotpos <= length(infname) then tstr := copy(infname,1,dotpos-1)
  49.   else
  50.   tstr := infname;
  51.   outfname := concat(tstr,'.pax');
  52. end;
  53. {---------------------------------------------------------------------------}
  54. procedure prompt_user;
  55. begin
  56.   writeln(
  57.   'PROGRAM ASC2PAS(C) 1988 BRUCE ROSENBERG,  NONCOMMERCIAL USE PERMITTED');
  58.   writeln;
  59.   writeln(
  60.   'ATTENTION: This program appends a .PAX extension to converted files.');
  61.    writeln;
  62.    if paramcount = 0 then
  63.    begin
  64.      write('Enter name of ASCII file to convert to pascal: ');
  65.      readln(infname);          { read entered name }
  66.    end else infname := paramstr(1);
  67.    name_outfile(infname,outfname);
  68. end;
  69. {---------------------------------------------------------------------------}
  70. procedure wrapup;
  71. begin
  72.   writeln;
  73.   writeln(
  74.   'File ',infname,' was converted to a pascal source file ',outfname,'.');
  75.   writeln;
  76.   writeln(
  77.   '        T H A N K S   F O R   U S I N G   A S C 2 P A S  ( TM )');
  78.   writeln;
  79.   writeln(
  80.   'PROGRAM ASC2PAS (C) 1988 BRUCE ROSENBERG,  NONCOMMERCIAL USE PERMITTED');
  81.  (*  for i := 1 to 5 do
  82.           begin
  83.           write(#7);  { beeps 5 times to signal p/o finished }
  84.           delay (1000);
  85.           end;
  86.    *)
  87. end;
  88. {---------------------------------------------------------------------------}
  89. procedure read_write;
  90. begin
  91.   assign(inf,infname); { assign that name to in }
  92.   reset(inf); { set pointer to 0 (beginning of disk file)}
  93.   assign(outf,outfname);
  94.   rewrite(outf);
  95.   writeln(outf,'BEGIN');
  96.   writeln(outf,'clrscr;');
  97.   while not eof(inf) do
  98.   begin               { printing next line }
  99.        LocOnLine := 1;  { position along the line (column) set to 1.}
  100.        readln(inf,line);  { reads line of data from named disk file }
  101.        if length(line) = 0 then writeln(outf,'writeln;');
  102.        for CharCount := 1 to length(line) do
  103.        begin
  104.          if ord(line[CharCount]) in PrnChars then {Elim. form feeds, esc, etc.}
  105.            begin
  106.              if LocOnLine = 1 then
  107.              begin
  108.                writeln(outf,'writeln(');
  109.                write(outf,'''');
  110.              end;
  111.              write(outf,line[CharCount]);   (* Does chars within line;      *)
  112.              if ord(line[CharCount]) = 39 then write(outf,#39);
  113.              (* above handles case of single quotes *)
  114.              if CharCount = length(line) then writeln(outf,''');');
  115.              LocOnLine := LocOnLine + 1
  116.            end;
  117.         end; { for-do line print }
  118.   end;  { while not eof }
  119. writeln(outf,
  120. '{  File, ',infname,', was transformed into pascal source by ASC2PAS (TM). }');
  121. writeln(outf,
  122. 'END.');
  123.   close(inf);
  124.   close(outf);
  125. end;
  126. {============================================================================}
  127. begin    { main program ASC2PAS }
  128.   clrscr;
  129.   prompt_user;
  130.   read_write;
  131.   wrapup;
  132. end.          { program ASC2PAS }
  133. {============================================================================}
  134.